﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发布材料 - 模切材料小管家</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            /* TDesign 工业品色彩系统 */
            --primary-color: #0052d9;
            --primary-light: #266fe8;
            --primary-dark: #003cab;
            --secondary-color: #f2f3ff;
            --accent-color: #e37318;
            --success-color: #00a870;
            --warning-color: #ed7b2f;
            --error-color: #d54941;
            
            /* 背景色系 */
            --bg-color-page: #f5f7fa;
            --bg-color-container: #ffffff;
            --bg-color-secondray: #f8f9fc;
            
            /* 边框和分割线 */
            --border-color: #e7e7e7;
            --border-color-light: #f0f0f0;
            --border-radius-small: 3px;
            --border-radius-medium: 6px;
            --border-radius-large: 9px;
            
            /* 文字色彩 */
            --text-primary: #1a1a1a;
            --text-secondary: #4e5969;
            --text-placeholder: #86909c;
            --text-disabled: #c9cdd4;
            
            /* 阴影系统 */
            --shadow-1: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
            --shadow-2: 0 1px 4px 0 rgba(0, 0, 0, 0.08);
            --shadow-3: 0 4px 8px 0 rgba(0, 0, 0, 0.12);
            
            /* 间距系统 */
            --space-1: 4px;
            --space-2: 8px;
            --space-3: 12px;
            --space-4: 16px;
            --space-5: 20px;
            --space-6: 24px;
            --space-8: 32px;
            --space-10: 40px;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        
        body {
            background-color: var(--bg-color-page);
            color: var(--text-primary);
            font-size: 14px;
            line-height: 1.5;
            padding-bottom: 120px;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        
        .container {
            max-width: 480px;
            margin: 0 auto;
            background: var(--bg-color-container);
            min-height: 100vh;
            box-shadow: var(--shadow-1);
            position: relative;
            overflow-x: hidden;
        }
        
        /* 头部样式 - TDesign 简约风格 */
        .header {
            background: var(--primary-color);
            color: white;
            padding: var(--space-4) var(--space-4) var(--space-5);
            position: relative;
            z-index: 10;
        }
        
        .top-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: var(--space-4);
        }
        
        .back-btn {
            font-size: 18px;
            cursor: pointer;
            opacity: 0.9;
            transition: opacity 0.2s ease;
        }
        
        .back-btn:hover {
            opacity: 1;
        }
        
        .page-title {
            font-weight: 500;
            font-size: 16px;
        }
        
        .actions {
            display: flex;
            gap: var(--space-5);
        }
        
        .actions i {
            font-size: 16px;
            cursor: pointer;
            opacity: 0.9;
            transition: opacity 0.2s ease;
        }
        
        .actions i:hover {
            opacity: 1;
        }
        
        /* 表单区域 - TDesign 简约风格 */
        .form-container {
            padding: var(--space-5) var(--space-4);
        }
        
        .form-section {
            background: var(--bg-color-container);
            border-radius: var(--border-radius-medium);
            margin-bottom: var(--space-4);
            box-shadow: var(--shadow-1);
            overflow: hidden;
            border: 1px solid var(--border-color-light);
        }
        
        .section-header {
            padding: var(--space-4);
            border-bottom: 1px solid var(--border-color-light);
            background: var(--bg-color-secondray);
        }
        
        .section-title {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
            display: flex;
            align-items: center;
        }
        
        .section-title i {
            margin-right: var(--space-2);
            color: var(--success-color);
            font-size: 14px;
        }
        
        .form-group {
            padding: var(--space-3) var(--space-4);
            border-bottom: 1px solid var(--border-color-light);
        }
        
        .form-group:last-child {
            border-bottom: none;
        }
        
        .form-label {
            display: block;
            margin-bottom: var(--space-2);
            font-weight: 500;
            color: var(--text-primary);
            font-size: 14px;
        }
        
        .required {
            color: var(--error-color);
        }
        
        .form-input {
            width: 100%;
            padding: var(--space-3);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            background: var(--bg-color-container);
            transition: all 0.2s ease;
        }
        
        .form-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        .form-textarea {
            width: 100%;
            padding: var(--space-3);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            background: var(--bg-color-container);
            resize: vertical;
            min-height: 80px;
            font-family: inherit;
            transition: all 0.2s ease;
        }
        
        .form-textarea:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        .form-select {
            width: 100%;
            padding: var(--space-3);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            background: var(--bg-color-container);
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .form-select:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        /* 上传区域 */
        .upload-area {
            border: 2px dashed var(--border-color);
            border-radius: var(--border-radius-medium);
            padding: var(--space-8);
            text-align: center;
            cursor: pointer;
            transition: all 0.2s ease;
            background: var(--bg-color-secondray);
        }
        
        .upload-area:hover {
            border-color: var(--primary-color);
            background: var(--secondary-color);
        }
        
        .upload-area i {
            font-size: 32px;
            margin-bottom: var(--space-2);
            color: var(--text-placeholder);
        }
        
        .upload-text {
            color: var(--text-secondary);
            font-size: 14px;
            margin-bottom: var(--space-1);
        }
        
        .upload-hint {
            color: var(--text-placeholder);
            font-size: 12px;
        }
        
        /* 图片上传区域 */
        .image-upload-container {
            margin-top: var(--space-2);
        }
        
        .image-upload-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: var(--space-2);
            margin-bottom: var(--space-2);
        }
        
        .image-upload-item {
            aspect-ratio: 1;
            border: 2px dashed var(--border-color);
            border-radius: var(--border-radius-medium);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s ease;
            background: var(--bg-color-secondray);
            position: relative;
        }
        
        .image-upload-item:hover {
            border-color: var(--primary-color);
            background: var(--secondary-color);
        }
        
        .image-upload-item i {
            font-size: 24px;
            color: var(--text-placeholder);
            margin-bottom: var(--space-1);
        }
        
        .image-upload-item .upload-text {
            font-size: 12px;
            color: var(--text-secondary);
        }
        
        .image-preview {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: var(--border-radius-small);
        }
        
        .image-remove {
            position: absolute;
            top: -6px;
            right: -6px;
            width: 20px;
            height: 20px;
            background: var(--error-color);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            cursor: pointer;
            border: 2px solid white;
        }
        
        /* 价格信息 */
        .price-group {
            display: flex;
            gap: var(--space-2);
        }
        
        .price-input {
            flex: 1;
        }
        
        .price-unit {
            width: 60px;
        }
        
        /* 库存信息 */
        .stock-group {
            display: flex;
            gap: var(--space-2);
        }
        
        .stock-input {
            flex: 1;
        }
        
        .stock-unit {
            width: 80px;
        }
        
        /* 规格/数量字段样式 */
        .spec-container {
            display: flex;
            flex-direction: column;
            gap: var(--space-3); /* 行间距 */
        }
        
        .spec-item {
            display: flex;
            align-items: center;
            background: var(--bg-color-container);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            overflow: hidden;
            transition: all 0.2s ease;
            height: 36px; /* TDesign标准高度 */
            min-width: 100px; /* 最小宽度 */
        }
        
        .spec-item:focus-within {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        .spec-input {
            border: none;
            padding: var(--space-3); /* TDesign标准内边距 */
            font-size: 14px; /* TDesign标准字体大小 */
            background: transparent;
            width: 70px; /* 合理的输入框宽度 */
            outline: none;
            height: 100%;
            flex: 1;
        }
        
        .spec-input::placeholder {
            color: var(--text-placeholder);
        }
        
        .spec-unit {
            padding: var(--space-2) var(--space-3); /* TDesign标准内边距 */
            background: var(--bg-color-secondray);
            color: var(--text-secondary);
            font-size: 12px; /* 合理的单位字体大小 */
            border-left: 1px solid var(--border-color-light);
            min-width: 32px; /* 合理的单位标签宽度 */
            text-align: center;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 500;
        }
        
        .add-spec-btn {
            width: 36px; /* 与规格项高度一致 */
            height: 36px; /* 与规格项高度一致 */
            border: 1px solid var(--primary-color);
            border-radius: 50%;
            background: var(--primary-color);
            color: white;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            font-size: 14px;
            flex-shrink: 0; /* 防止按钮被压缩 */
        }
        
        .add-spec-btn:hover {
            background: var(--primary-light);
            transform: scale(1.05);
        }
        
        .remove-spec-btn {
            width: 28px; /* 适中的删除按钮尺寸 */
            height: 28px; /* 适中的删除按钮尺寸 */
            border: 1px solid var(--error-color);
            border-radius: 50%;
            background: var(--error-color);
            color: white;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            font-size: 12px;
            margin-left: var(--space-2);
            flex-shrink: 0; /* 防止按钮被压缩 */
        }
        
        .remove-spec-btn:hover {
            background: #c0392b;
            transform: scale(1.05);
        }
        
        /* 地址联动 */
        .address-group {
            display: flex;
            flex-direction: column;
            gap: var(--space-2);
        }
        
        .address-row {
            display: flex;
            gap: var(--space-2);
        }
        
        .address-select {
            flex: 1;
        }
        
        /* 标签选择 */
        .tag-container {
            display: flex;
            flex-wrap: wrap;
            gap: var(--space-2);
            margin-top: var(--space-2);
        }
        
        .tag {
            background: var(--bg-color-secondray);
            color: var(--text-secondary);
            padding: var(--space-1) var(--space-3);
            border-radius: var(--border-radius-small);
            font-size: 12px;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.34, 0.69, 0.1, 1);
            border: 1px solid var(--border-color-light);
        }
        
        .tag:hover {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }
        
        .tag.selected {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }
        
        /* 底部操作栏 - TDesign 简约风格 */
        .bottom-actions {
            position: fixed;
            bottom: 64px;
            left: 0;
            right: 0;
            background: var(--bg-color-container);
            padding: var(--space-4);
            border-top: 1px solid var(--border-color-light);
            display: flex;
            gap: var(--space-2);
            z-index: 100;
            max-width: 480px;
            margin: 0 auto;
        }
        
        .btn {
            width: 100%;
            padding: var(--space-3);
            border: none;
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .btn-secondary {
            background: var(--bg-color-secondray);
            color: var(--text-secondary);
            border: 1px solid var(--border-color-light);
        }
        
        .btn-secondary:hover {
            background: var(--border-color-light);
        }
        
        .btn-primary {
            background: var(--primary-color);
            color: white;
        }
        
        .btn-primary:hover {
            background: var(--primary-dark);
        }
        
        /* 底部导航栏 - TDesign 简约风格 */
        .tabbar {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--bg-color-container);
            border-top: 1px solid var(--border-color);
            display: flex;
            z-index: 100;
            max-width: 480px;
            margin: 0 auto;
            height: 64px;
        }
        
        .tab-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: var(--space-2) 0;
            cursor: pointer;
            transition: color 0.2s ease;
            color: var(--text-placeholder);
        }
        
        .tab-item.active {
            color: var(--primary-color);
        }
        
        .tab-item:hover {
            color: var(--primary-light);
        }
        
        .tab-item i {
            font-size: 18px;
            margin-bottom: var(--space-1);
        }
        
        .tab-item span {
            font-size: 10px;
        }
        
        /* 提示信息 */
        .form-hint {
            color: var(--text-placeholder);
            font-size: 12px;
            margin-top: var(--space-1);
        }
        
        .form-error {
            color: var(--error-color);
            font-size: 12px;
            margin-top: var(--space-1);
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 头部区域 -->
        <div class="header">
            <div class="top-bar">
                <div class="back-btn" onclick="history.back()">
                    <i class="fas fa-arrow-left"></i>
                </div>
                <div class="page-title">发布材料</div>
                <div class="actions">
                    <i class="fas fa-question-circle" onclick="showHelp()"></i>
                </div>
            </div>
        </div>
        
        <!-- 表单区域 -->
        <div class="form-container">
            <!-- 材料信息 -->
            <div class="form-section">
                <div class="section-header">
                    <div class="section-title">
                        <i class="fas fa-cube"></i>
                        材料信息
                    </div>
                </div>
                
                
                <div class="form-group">
                    <label class="form-label">产品类别 <span class="required">*</span></label>
                    <select class="form-select">
                        <option value="">请选择产品类别</option>
                        <option value="tape">胶带类</option>
                        <option value="film">薄膜类</option>
                        <option value="adhesive">胶粘剂</option>
                        <option value="foam">泡棉类</option>
                        <option value="paper">纸张类</option>
                        <option value="other">其他</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label class="form-label">产品名称 <span class="required">*</span></label>
                    <select class="form-select">
                        <option value="">请选择产品名称</option>
                        <option value="bopp-tape">BOPP单面胶带</option>
                        <option value="masking-tape">美纹纸胶带</option>
                        <option value="double-sided-tape">双面胶带</option>
                        <option value="packaging-tape">包装胶带</option>
                        <option value="electrical-tape">电工胶带</option>
                        <option value="other">其他</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label class="form-label">产品型号 <span class="required">*</span></label>
                    <input type="text" class="form-input" placeholder="请输入产品型号">
                </div>
                
                <div class="form-group">
                    <label class="form-label">技术参数</label>
                    <div class="upload-area" onclick="uploadTechParams()">
                        <i class="fas fa-cloud-upload-alt"></i>
                        <div class="upload-text">点击上传技术参数</div>
                        <div class="upload-hint">支持JPG、PNG、PDF格式，文件大小不超过10MB</div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="form-label">产品图片</label>
                    <div class="image-upload-container">
                        <div class="image-upload-grid" id="imageUploadGrid">
                            <div class="image-upload-item" onclick="uploadProductImage()">
                                <i class="fas fa-plus"></i>
                                <div class="upload-text">添加图片</div>
                            </div>
                        </div>
                        <div class="upload-hint">最多上传3张图片，支持JPG、PNG格式，每张不超过5MB</div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="form-label">规格/数量 <span class="required">*</span></label>
                    <div class="spec-container">
                        <div class="spec-row" style="display: flex; gap: var(--space-2); align-items: center;">
                            <div class="spec-item">
                                <input type="number" class="spec-input" placeholder="0">
                                <span class="spec-unit">mm</span>
                            </div>
                            <div class="spec-item">
                                <input type="number" class="spec-input" placeholder="0">
                                <span class="spec-unit">m</span>
                            </div>
                            <button type="button" class="add-spec-btn" onclick="addSpecItem()">
                                <i class="fas fa-plus"></i>
                            </button>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="form-label">备注</label>
                    <textarea class="form-textarea" placeholder="请输入备注信息（可选）"></textarea>
                </div>
            </div>
            
            
            <!-- 联系方式 -->
            <div class="form-section">
                <div class="section-header">
                    <div class="section-title">
                        <i class="fas fa-phone"></i>
                        联系方式
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="form-label">联系人 <span class="required">*</span></label>
                    <input type="text" class="form-input" placeholder="请输入联系人姓名">
                </div>
                
                <div class="form-group">
                    <label class="form-label">联系电话 <span class="required">*</span></label>
                    <input type="tel" class="form-input" placeholder="请输入联系电话">
                </div>
                
                
                <div class="form-group">
                    <label class="form-label">邮箱</label>
                    <input type="email" class="form-input" placeholder="请输入邮箱地址（可选）">
                </div>
                
                <div class="form-group">
                    <label class="form-label">所在地 <span class="required">*</span></label>
                    <div class="address-group">
                        <div class="address-row">
                            <select class="form-select address-select" id="province">
                                <option value="">请选择省份</option>
                                <option value="beijing">北京市</option>
                                <option value="shanghai">上海市</option>
                                <option value="guangdong">广东省</option>
                                <option value="jiangsu">江苏省</option>
                                <option value="zhejiang">浙江省</option>
                                <option value="other">其他</option>
                            </select>
                            <select class="form-select address-select" id="city">
                                <option value="">请选择城市</option>
                            </select>
                        </div>
                        <div class="address-row">
                            <select class="form-select address-select" id="district">
                                <option value="">请选择区县</option>
                            </select>
                        </div>
                        <textarea class="form-textarea" placeholder="请输入详细地址（街道、门牌号等）"></textarea>
                    </div>
                </div>
            </div>
            
        </div>
        
        <!-- 底部操作栏 -->
        <div class="bottom-actions">
            <button class="btn btn-primary" onclick="submitForm()">发布材料</button>
        </div>
        
        <!-- 底部导航 -->
        <div class="tabbar">
            <div class="tab-item" onclick="location.href='home.html'">
                <i class="fas fa-home"></i>
                <span>首页</span>
            </div>
            <div class="tab-item" onclick="location.href='search-results.html'">
                <i class="fas fa-search"></i>
                <span>求购</span>
            </div>
            <div class="tab-item active">
                <i class="fas fa-plus-circle"></i>
                <span>发布</span>
            </div>
            <div class="tab-item" onclick="location.href='consultation.html'">
                <i class="fas fa-comments"></i>
                <span>客服</span>
            </div>
            <div class="tab-item" onclick="location.href='profile.html'">
                <i class="fas fa-user"></i>
                <span>我的</span>
            </div>
        </div>
    </div>
    
    <script>
        // 上传技术参数
        function uploadTechParams() {
            console.log('上传技术参数');
            // 模拟上传成功
            const uploadArea = document.querySelector('.upload-area');
            uploadArea.innerHTML = `
                <i class="fas fa-check-circle" style="color: var(--success-color);"></i>
                <div class="upload-text">技术参数上传成功</div>
                <div style="margin-top: var(--space-2); padding: var(--space-2); background: var(--bg-color-container); border-radius: var(--border-radius-small); border: 1px solid var(--border-color-light); display: flex; align-items: center; justify-content: center; gap: var(--space-2);">
                    <i class="fas fa-file-pdf" style="color: var(--error-color);"></i>
                    <span style="font-size: 12px; color: var(--text-secondary);">tech-params.pdf</span>
                    <i class="fas fa-times" style="color: var(--error-color); cursor: pointer;" onclick="removeFile(this)"></i>
                </div>
            `;
        }
        
        // 删除文件
        function removeFile(element) {
            const uploadArea = element.closest('.upload-area');
            uploadArea.innerHTML = `
                <i class="fas fa-cloud-upload-alt"></i>
                <div class="upload-text">点击上传文件</div>
                <div class="upload-hint">支持JPG、PNG、PDF格式，文件大小不超过10MB</div>
            `;
        }
        
        // 产品图片上传
        let uploadedImages = [];
        
        function uploadProductImage() {
            if (uploadedImages.length >= 3) {
                alert('最多只能上传3张图片');
                return;
            }
            
            console.log('上传产品图片');
            // 模拟上传成功
            const imageUrl = `https://via.placeholder.com/150x150?text=Product+${uploadedImages.length + 1}`;
            uploadedImages.push(imageUrl);
            updateImageGrid();
        }
        
        function updateImageGrid() {
            const grid = document.getElementById('imageUploadGrid');
            grid.innerHTML = '';
            
            // 显示已上传的图片
            uploadedImages.forEach((imageUrl, index) => {
                const imageItem = document.createElement('div');
                imageItem.className = 'image-upload-item';
                imageItem.innerHTML = `
                    <img src="${imageUrl}" alt="产品图片" class="image-preview">
                    <div class="image-remove" onclick="removeProductImage(${index})">
                        <i class="fas fa-times"></i>
                    </div>
                `;
                grid.appendChild(imageItem);
            });
            
            // 如果还有空间，显示添加按钮
            if (uploadedImages.length < 3) {
                const addItem = document.createElement('div');
                addItem.className = 'image-upload-item';
                addItem.onclick = uploadProductImage;
                addItem.innerHTML = `
                    <i class="fas fa-plus"></i>
                    <div class="upload-text">添加图片</div>
                `;
                grid.appendChild(addItem);
            }
        }
        
        function removeProductImage(index) {
            uploadedImages.splice(index, 1);
            updateImageGrid();
        }
        
        // 规格/数量管理
        let specCounter = 2; // 初始已有2个规格项
        
        function addSpecItem() {
            const specContainer = document.querySelector('.spec-container');
            
            // 创建一行包含mm和m的规格项
            const specRow = document.createElement('div');
            specRow.className = 'spec-row';
            specRow.style.cssText = 'display: flex; gap: var(--space-2); align-items: center;';
            
            // 创建mm规格项
            const mmItem = document.createElement('div');
            mmItem.className = 'spec-item';
            mmItem.innerHTML = `
                <input type="number" class="spec-input" placeholder="0">
                <span class="spec-unit">mm</span>
            `;
            
            // 创建m规格项
            const mItem = document.createElement('div');
            mItem.className = 'spec-item';
            mItem.innerHTML = `
                <input type="number" class="spec-input" placeholder="0">
                <span class="spec-unit">m</span>
            `;
            
            // 创建删除按钮
            const removeBtn = document.createElement('button');
            removeBtn.type = 'button';
            removeBtn.className = 'remove-spec-btn';
            removeBtn.style.cssText = 'margin-left: 8px;';
            removeBtn.innerHTML = '<i class="fas fa-times"></i>';
            removeBtn.onclick = function() { removeSpecRow(this); };
            
            // 组装行
            specRow.appendChild(mmItem);
            specRow.appendChild(mItem);
            specRow.appendChild(removeBtn);
            
            // 在第一行后插入新行
            const firstRow = specContainer.querySelector('.spec-row');
            specContainer.insertBefore(specRow, firstRow.nextSibling);
            specCounter++;
        }
        
        function removeSpecRow(button) {
            const specRow = button.parentElement;
            specRow.remove();
            specCounter--;
        }
        
        // 地址数据
        const addressData = {
            'beijing': {
                'name': '北京市',
                'cities': {
                    'beijing': { 'name': '北京市', 'districts': { 'dongcheng': '东城区', 'xicheng': '西城区', 'chaoyang': '朝阳区', 'haidian': '海淀区' } }
                }
            },
            'shanghai': {
                'name': '上海市',
                'cities': {
                    'shanghai': { 'name': '上海市', 'districts': { 'huangpu': '黄浦区', 'xuhui': '徐汇区', 'changning': '长宁区', 'jingan': '静安区' } }
                }
            },
            'guangdong': {
                'name': '广东省',
                'cities': {
                    'guangzhou': { 'name': '广州市', 'districts': { 'yuexiu': '越秀区', 'liwan': '荔湾区', 'haizhu': '海珠区', 'tianhe': '天河区' } },
                    'shenzhen': { 'name': '深圳市', 'districts': { 'futian': '福田区', 'luohu': '罗湖区', 'nanshan': '南山区', 'yantian': '盐田区' } }
                }
            },
            'jiangsu': {
                'name': '江苏省',
                'cities': {
                    'nanjing': { 'name': '南京市', 'districts': { 'xuanwu': '玄武区', 'qinhuai': '秦淮区', 'jianye': '建邺区', 'gulou': '鼓楼区' } },
                    'suzhou': { 'name': '苏州市', 'districts': { 'gusu': '姑苏区', 'wuzhong': '吴中区', 'xiangcheng': '相城区', 'kunshan': '昆山市' } }
                }
            },
            'zhejiang': {
                'name': '浙江省',
                'cities': {
                    'hangzhou': { 'name': '杭州市', 'districts': { 'shangcheng': '上城区', 'xiacheng': '下城区', 'jianggan': '江干区', 'gongshu': '拱墅区' } },
                    'ningbo': { 'name': '宁波市', 'districts': { 'haishu': '海曙区', 'jiangbei': '江北区', 'beilun': '北仑区', 'zhenhai': '镇海区' } }
                }
            }
        };
        
        // 初始化地址选择
        function initAddressSelect() {
            const provinceSelect = document.getElementById('province');
            const citySelect = document.getElementById('city');
            const districtSelect = document.getElementById('district');
            
            // 省份变化
            provinceSelect.addEventListener('change', function() {
                const provinceValue = this.value;
                citySelect.innerHTML = '<option value="">请选择城市</option>';
                districtSelect.innerHTML = '<option value="">请选择区县</option>';
                
                if (provinceValue && addressData[provinceValue]) {
                    const cities = addressData[provinceValue].cities;
                    for (const cityKey in cities) {
                        const option = document.createElement('option');
                        option.value = cityKey;
                        option.textContent = cities[cityKey].name;
                        citySelect.appendChild(option);
                    }
                }
            });
            
            // 城市变化
            citySelect.addEventListener('change', function() {
                const provinceValue = provinceSelect.value;
                const cityValue = this.value;
                districtSelect.innerHTML = '<option value="">请选择区县</option>';
                
                if (provinceValue && cityValue && addressData[provinceValue] && addressData[provinceValue].cities[cityValue]) {
                    const districts = addressData[provinceValue].cities[cityValue].districts;
                    for (const districtKey in districts) {
                        const option = document.createElement('option');
                        option.value = districtKey;
                        option.textContent = districts[districtKey];
                        districtSelect.appendChild(option);
                    }
                }
            });
        }
        
        // 页面加载完成后初始化地址选择
        document.addEventListener('DOMContentLoaded', function() {
            initAddressSelect();
        });
        
        // 提交表单
        function submitForm() {
            console.log('发布材料');
            if (validateForm()) {
                // 若无图片，生成公司简称头像占位（示例逻辑）
                if (uploadedImages.length === 0) {
                    console.log('未上传产品图片，将使用公司简称头像占位');
                }
                alert('材料产品已发布');
            } else {
                alert('请填写所有必填项');
            }
        }
        
        // 显示帮助
        function showHelp() {
            alert('发布材料产品帮助信息');
        }
        
        // 底部导航切换
        document.querySelectorAll('.tab-item').forEach(item => {
            item.addEventListener('click', function() {
                document.querySelectorAll('.tab-item').forEach(t => t.classList.remove('active'));
                this.classList.add('active');
            });
        });
        
        // 表单验证
        function validateForm() {
            const requiredFields = document.querySelectorAll('.form-input[required], .form-select[required], .form-textarea[required]');
            let isValid = true;
            
            requiredFields.forEach(field => {
                if (!field.value.trim()) {
                    field.style.borderColor = 'var(--error-color)';
                    isValid = false;
                } else {
                    field.style.borderColor = 'var(--border-color)';
                }
            });
            
            // 产品图片非必填：若未上传，将用公司简称生成头像展示
            
            return isValid;
        }
        
        // 提交按钮点击事件
        document.querySelector('.btn-primary').addEventListener('click', function() {
            if (validateForm()) {
                submitForm();
            } else {
                alert('请填写所有必填项');
            }
        });
    </script>
</body>
</html>


